<?php

/**
 * Access Control List
 * This class defines the different access controls needed to access specific resources within the application
 */

class Model_ACL extends  Zend_Acl {
	
	public function __construct() {


                //User Roles
		$this->addRole(new Zend_Acl_Role ('guest'));
		$this->addRole(new Zend_Acl_Role('user'), 'guest');
		$this->addRole(new Zend_Acl_Role('admin'), 'user');
		
		//Resources
		$this->add(new Zend_Acl_Resource('student'))
			 ->add(new Zend_Acl_Resource('student:index'), 'student')
                         ->add(new Zend_Acl_Resource('student:course'), 'student')
                         ->add(new Zend_Acl_Resource('student:assessment'), 'student')
                         ->add(new Zend_Acl_Resource('student:grade'), 'student')
                         ->add(new Zend_Acl_Resource('student:scale'), 'student')
                         ->add(new Zend_Acl_Resource('student:tracker'), 'student')
                         ->add(new Zend_Acl_Resource('student:gpa'), 'student');


                               
                $this->add(new Zend_Acl_Resource('community'))
			 ->add(new Zend_Acl_Resource('community:index'), 'community')
			 ->add(new Zend_Acl_Resource('community:ratecourse'), 'community');
			 			 

                $this->add(new Zend_Acl_Resource('default'))
			 ->add(new Zend_Acl_Resource('default:index'), 'default')
			->add(new Zend_Acl_Resource('default:error'), 'default')
			->add(new Zend_Acl_Resource('default:users'), 'default')
			->add(new Zend_Acl_Resource('default:account'), 'default');

                //Admin Resource
		$this->add(new Zend_Acl_Resource('admin'))
			 ->add(new Zend_Acl_Resource('admin:usermanagement'), 'admin');

                /**
		 * Setting up dummy permissions
		 */
		$this->allow('guest', 'default:index', 'index')
			 ->allow('guest', 'default:error', 'error')
			 ->allow('guest', 'default:users', array('login', 'register'))
			 ->allow('guest', 'default:index', 'about')
                         ->allow('guest','student:index')
                         ->deny('guest','student:index','welcome');


                $this->allow('user', 'default:index', 'index')
			 ->allow('user', 'community:index', 'index')
			 ->allow('user', 'default:users', array('logout'))
			 ->allow('user', 'default:account', array('index'))
			 ->allow('user', 'community:ratecourse', array('index', 'rate', 'getdepts', 'getcourses', 'getperiod', 'rate', 'viewcomments', 'viewaverage'))
			 ->deny('user', 'default:users', array('login', 'register'));

		$this->allow('user', 'default:index', 'index')
			 ->allow('user', 'student:index', 'index')
			 ->allow('user', 'default:users', array('logout'))
			 ->allow('user', 'default:account', array('index'))
                         ->allow('user', 'student:course',array('index', 'add', 'view', 'edit','delete'))
                         ->allow('user', 'student:assessment', array('index', 'add', 'view', 'edit', 'delete'))
                         ->allow('user', 'student:grade', array('index', 'add', 'view', 'edit', 'delete', 'addmore'))
                         ->allow('user', 'student:scale', array('index', 'Add', 'view', 'Edit', 'delete'))
                         ->allow('user', 'student:gpa', array('index', 'view'))
                         ->allow('user', 'student:tracker', array('index'))
                        ->allow('user', 'student:index', array('index','welcome'))
                         ->deny('user', 'default:users', array('login', 'register'));

		$this->allow('admin', 'admin:usermanagement', array('listusers'))
                         ->allow('admin', 'student:gpa', array('index, view'))
                         
                ;
			 

	}
	
}
